package com.drinks.yiniang.ui.activity.user.friends;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.drinks.yiniang.R;
import com.drinks.yiniang.adapter.viewpager.CodeTabFragmentAdapter;
import com.drinks.yiniang.ui.fragment.user.friends.FriendsListFragment;
import com.hansen.library.Constants;
import com.hansen.library.ui.activity.BaseTranBarActivity;
import com.hansen.library.ui.fragment.BaseLazyFragment;
import com.hansen.library.listener.OnNavgationBarClickListener;
import com.hansen.library.pickerview.bean.CodeValueBean;
import com.hansen.library.ui.widget.nav.NavigationBarLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的好友列表页面
 * @author han
 * @date 2019/09/08
 */
public class MyFriendsActivity extends BaseTranBarActivity implements OnNavgationBarClickListener {

    //nav
    private NavigationBarLayout nav_bar_my_friends;
    private TabLayout tab_my_friends;
    private ViewPager vp_my_friends;

    private CodeTabFragmentAdapter mTabFragmentAdapter;

    private List<BaseLazyFragment> mFragments;

    private List<CodeValueBean> mTabs;

    @Override
    protected void initView() {
        nav_bar_my_friends = findViewById(R.id.nav_bar_my_friends);

        tab_my_friends = findViewById(R.id.tab_my_friends);

        vp_my_friends = findViewById(R.id.vp_my_friends);
    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        mContext = this;

        initTabAndAdapter();
    }

    private void initTabAndAdapter() {
        mTabs = new ArrayList<>(2);

        mTabs.add(new CodeValueBean(Constants.TYPE_FRIENDS_FOLLOW, getString(R.string.text_follow)));
        mTabs.add(new CodeValueBean(Constants.TYPE_FRIENDS_FANS, getString(R.string.text_fans)));

        mFragments = new ArrayList<>(mTabs.size());

        for(int i = 0; i < mTabs.size(); i++) {
            tab_my_friends.addTab(tab_my_friends.newTab().setText(mTabs.get(i).getValue()));

            mFragments.add(FriendsListFragment.newInstance(mTabs.get(i).getCode()));
        }

        //初始化viewpager数据
        mTabFragmentAdapter = new CodeTabFragmentAdapter(getSupportFragmentManager(), mFragments, mTabs);

        vp_my_friends.setAdapter(mTabFragmentAdapter);
        tab_my_friends.setupWithViewPager(vp_my_friends);
    }

    @Override
    protected void initListener() {
        nav_bar_my_friends.setOnNavgationBarClickListener(this);
    }

    @Override
    public void widgetClick(View v) {

    }

    @Override
    public int getTranBarResID() {
        return R.layout.activity_my_friends;
    }

    @Override
    public void onBackClick(View v) {
        finish();
    }

    @Override
    public void onEditClick(View v) {

    }
}
